<!--#include file="conn.asp"-->
<!--#include file="system31.asp"-->
<!--#include file="system35.asp"-->

<%call LevelCheck(AdminLevel,UrlLoginFile)%>

<!--#include file="upload_inc.asp"-->

<%

dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr
dim PhotoUrlID
msg=""
FoundErr=false
EnableUpload=false
%>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 </head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
<%
if EnableUploadFile=False  then
	response.write "系统未开放文件上传功能"
else
	call upload_0()  '使用化境无组件上传类
end if
 %>
</body>
</html>
<%
sub upload_0()    '使用化境无组件上传类
	set upload=new upfile_class ''建立上传对象
	upload.GetData(104857600)   '取得上传数据,限制最大上传100M
	if upload.err > 0 then  '如果出错
		select case upload.err
			case 1
				response.write "请先选择你要上传的文件！"
			case 2
				response.write "你上传的文件总大小超出了最大限制（100M）"
		end select
		response.end
	end if
	PhotoUrlID=killint(trim(upload.form("PhotoUrlID")),0,0,3)
	SavePath = SaveUpFilesPath   '存放上传文件的目录

	if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
		
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		oFileSize=ofile.filesize
		if oFileSize<100 then
			msg="请先选择你要上传的文件！"
			FoundErr=True
		elseif oFileSize>(MaxFileSize*1024) then
 			msg="文件大小超过了限制，最大只能上传" & CStr(MaxFileSize) & "K的文件！"
			FoundErr=true
		end if

		fileExt=lcase(ofile.FileExt)
		arrUpFileType=split(UpFileType,"|")
		Dim i,strJS,File
		for i=0 to ubound(arrUpFileType)
			if fileEXT=trim(arrUpFileType(i)) then
				EnableUpload=true
				exit for
			end if
		next
		if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
			EnableUpload=false
		end if
		if EnableUpload=false then
			msg="这种文件类型不允许上传！\n\n只允许上传这几种文件类型：" & UpFileType
			FoundErr=true
		end if
		
		
		strJS="<SCRIPT language=javascript>try{" & vbcrlf
		if FoundErr<>true then
			randomize
			ranNum=int(900*rnd)+100
			filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
			ofile.SaveToFile Server.mappath(FileName)   '保存文件

			filename =replace(filename,"../","")
			Dim editFile
			editFile = "../../" & fileName
			select case fileEXT
			case "rar":
			
			strJS=strJS & "parent.document.form.message.value +='[upload=" & fileName & "]附件上传[/upload]';" & vbcrlf
			strJS=strJS & "parent.window.frames[""eWebEditor1""].frames[""HtmlEditor""].document.getElementsByTagName(""BODY"")[0].innerHTML +='<a href=" & editFile & ">附件上传</a>';" & vbcrlf

			case "zip":
			
			strJS=strJS & "parent.document.form.message.value +='[upload=" & fileName & "]附件上传[/upload]';" & vbcrlf
			strJS=strJS & "parent.window.frames[""eWebEditor1""].frames[""HtmlEditor""].document.getElementsByTagName(""BODY"")[0].innerHTML +='<a href=" & editFile & ">附件上传</a>';" & vbcrlf

			case "doc":
			
			strJS=strJS & "parent.document.form.message.value +='[upload=" & fileName & "]附件上传[/upload]';" & vbcrlf
			strJS=strJS & "parent.window.frames[""eWebEditor1""].frames[""HtmlEditor""].document.getElementsByTagName(""BODY"")[0].innerHTML +='<a href=" & editFile & ">附件上传</a>';" & vbcrlf

			case "txt":
			
			strJS=strJS & "parent.document.form.message.value +='[upload=" & fileName & "]附件上传[/upload]';" & vbcrlf
			strJS=strJS & "parent.window.frames[""eWebEditor1""].frames[""HtmlEditor""].document.getElementsByTagName(""BODY"")[0].innerHTML +='<a href=" & editFile & ">附件上传</a>';" & vbcrlf

			
			case else:
			
			strJS=strJS & "parent.document.form.message.value +='[img]" & fileName & "[/img]';" & vbcrlf
			strJS=strJS & "parent.window.frames[""eWebEditor1""].frames[""HtmlEditor""].document.getElementsByTagName(""BODY"")[0].innerHTML +='<img src=""" &  editFile & " "">';" & vbcrlf

			

			End select 
		else
			strJS=strJS & "alert('" & msg & "');" & vbcrlf
		end if
		strJS=strJS & "}catch(e){;}alert('上传"&fileName&"完成.');history.go(-1);" & vbcrlf
		strJS=strJS & "</script>" & vbcrlf
		response.write strJS
		
		set file=nothing
	next
	set upload=nothing
end sub
%>
